import POJO.People;
import lombok.SneakyThrows;
import org.junit.Test;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.zip.GZIPOutputStream;

public class test {
    //普通

    @Test
    public void test1() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, InvocationTargetException, IllegalAccessException, IOException {
        People people = new People();
        long startTime = System.currentTimeMillis();

        for (int i = 0; i < 2000000000; i++) {
            people.getName();
        }

        long endTime = System.currentTimeMillis();

        System.out.println("普通耗时："+(endTime-startTime)/100);
        //----------------------------------------------------
        Class c1 = Class.forName("POJO.People");
        //Class c1 = people.getClass();
        people = (People)c1.newInstance();
        Method getName = c1.getDeclaredMethod("getName");
        //getName.setAccessible(true);
        startTime = System.currentTimeMillis();

        for (int i = 0; i < 2000000000; i++) {
            getName.invoke(people,null);
        }

        endTime = System.currentTimeMillis();

        System.out.println("反射耗时："+(endTime-startTime)/100);
        //----------------------------------------------------
        c1 = Class.forName("POJO.People");
        //Class c1 = people.getClass();
        people = (People)c1.newInstance();
        getName = c1.getDeclaredMethod("getName");
        getName.setAccessible(true);
        startTime = System.currentTimeMillis();

        for (int i = 0; i < 2000000000; i++) {
            getName.invoke(people,null);
        }

        endTime = System.currentTimeMillis();

        System.out.println("关闭检测的反射耗时："+(endTime-startTime)/100);


        new BufferedWriter(new FileWriter("s"));
        //new BufferedReader(new FileInputStream("s"));
        new GZIPOutputStream(new FileOutputStream(""));
    }

  /*  //反射
    @Test
    public void test2() throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, InstantiationException {
        Class c1 = Class.forName("POJO.People");
        //Class c1 = people.getClass();
        People people = (People)c1.newInstance();
        Method getName = c1.getDeclaredMethod("getName");
        //getName.setAccessible(true);
        long startTime = System.currentTimeMillis();

        for (int i = 0; i < 2000000000; i++) {
            getName.invoke(people,null);
        }

        long endTime = System.currentTimeMillis();

        System.out.println("反射耗时："+(endTime-startTime)/100);
    }

    //关闭检测
    @Test
    public void test3() throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, InstantiationException {
        Class c1 = Class.forName("POJO.People");
        //Class c1 = people.getClass();
        People people = (People)c1.newInstance();
        Method getName = c1.getDeclaredMethod("getName");
        getName.setAccessible(true);
        long startTime = System.currentTimeMillis();

        for (int i = 0; i < 2000000000; i++) {
            getName.invoke(people,null);
        }

        long endTime = System.currentTimeMillis();

        System.out.println("关闭检测的反射耗时："+(endTime-startTime)/100);
    }*/
}
